<template>
  <el-container class="home-wrapper">
    <el-header>
      <el-row>
        <el-col :span="8" class="logo">
          <img src="@/assets/logo.png" alt="黑马logo">
        </el-col>
        <el-col :span="8">
          <h1 class="title">电商后台管理系统</h1>
        </el-col>
        <el-col :span="8">
          <div class="welcome">
            <span>欢迎上海25期学员见面会</span>
            <a href="#" @click.prevent="logout">退出</a>
          </div>
        </el-col>
      </el-row>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu :router="true" default-active="/home/users" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" background-color="#545c64" text-color="#fff" active-text-color="#ffd04b">
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>用户管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/home/users">
                <template slot="title">
                  <i class="el-icon-menu"></i>
                  <span>用户列表</span>
                </template>
              </el-menu-item>
              <el-menu-item index="1-2">用户列表</el-menu-item>
              <el-menu-item index="1-3">用户列表</el-menu-item>
            </el-menu-item-group>
          </el-submenu>

          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>用户管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="2-1">用户列表</el-menu-item>
              <el-menu-item index="2-2">用户列表</el-menu-item>
              <el-menu-item index="2-3">用户列表</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>

      </el-aside>
      <el-main>
       <router-view/>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  methods: {
    //退出功能
    //1、弹出确认对话框
    //2、用户点击确认
    //2-1、跳回登陆页面
    //2-2、清除token
    logout() {
      this.$confirm("你是否确认退出?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          localStorage.removeItem("token");
          this.$router.push("/login");
        })
        .catch(() => {});
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    }
  }
};
</script>

<style scoped lang="less">
.home-wrapper {
  height: 100%;
  .el-header {
    padding: 0;
    background-color: #b3c1cd;
    color: #333;
    text-align: center;
    .logo {
      text-align: left;
    }
    .title {
      line-height: 60px;
      margin: 0;
      color: #fff;
      font-size: 40px;
    }
    .welcome {
      text-align: right;
      padding-right: 30px;
      line-height: 60px;
      font-weight: bold;
      a {
        text-decoration: none;
        color: #b07a17;
      }
    }
  }

  .el-aside {
    background-color: #545c64;
    color: #333;
    // text-align: center;
    line-height: 200px;
  }

  .el-main {
    background-color: #eaeef1;
    color: #333;
    // line-height: 160px;
  }
  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }

  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }
}
</style>
